<?php
require_once 'Zend/Controller/Action.php';

class CronController extends App_Zend_Controller_Action_Shop
{
	public function indexAction()
	{
		
	}
	
 	public function flashsaleAction()
 	{
 		
 		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		
		$file = MY_ROOT . '/php_config/flash_sale_time.ini';
		$arr = parse_ini_file($file, 1);
		$time = strtotime(date('Y-m-d H:i', time()));
		$date = date('Y-m-d', time());
		$flag = 0;
		foreach ($arr as $v) {			
			$beginTime = strtotime($date . ' ' . $v['begin']);
			$endTime = strtotime($date . ' ' . $v['end']);
			if ($beginTime >= $endTime) {
				continue;
			}
			if ($beginTime == $time) {
				$flag = 1;
			}
		
			if ($flag) {
				break;
			}
		}
		$flashSale = new CFlashsales();
		$flashSale->resumeExpirePrice();//恢复过期产品价格并下架
		echo 'aaa<br />';
		$fp = fopen(MY_ROOT . '/lock.lock' , 'w');	
		if (flock($fp , LOCK_EX)) {
			$current = $flashSale->getCurrentBeginTime();			
			if ($flag && ($current < $time)) {
				$flashSale->resumeProductPrice(); //恢复价格，下架产品
				$flashSale->productSale($beginTime, $endTime); //生成新产品上架
			}
			flock($fp , LOCK_UN);    
		}
		echo 'ok';
 	}


}